<template>
  <div>
    <el-container>
      <!-- <el-header class="homeHeader">
        <a href="/#/admin/home"><div class="title">小L星光站后台</div></a>
        <el-dropdown class="userInfo" @command="commandHandler">
          @command="commandHandler" 点击菜单项触发的事件回调
          <span class="el-dropdown-link">
            {{ user.name }}
            <i><img :src="user.avatar" alt="" /></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
            <el-dropdown-item command="setting">设置</el-dropdown-item>
            disabled:禁用的 divided:有分隔线
            <el-dropdown-item command="logout" divided
              >注销登录</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </el-header> -->
      <el-container class="menu-container">
        <el-aside width="228px">
          <el-menu
            router
            background-color="#4561C9"
            style="height: 100vh"
            text-color="#fff"
            active-text-color="#ffd04b"
          >
            <el-menu-item index="/">
              <i class="el-icon-menu"></i>
              <span slot="title">首页</span>
            </el-menu-item>
            <!--这个遍历拿到的是index.js里面的routers地址数组 -->
            <!-- !item.hidden 是将home和login的路由名隐藏，不需要在左侧菜单渲染出来 -->
            <el-submenu
              :index="item.path"
              v-for="(item, index) in routers"
              :key="index"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item
                :index="child.path"
                v-for="(child, indexj) in item.children"
                :key="indexj"
              >
                {{ child.name }}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
      </el-container>
      <el-container class="main-container">
        <el-main>
          <!-- 面包屑 -->
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>

            <el-breadcrumb-item>{{
              this.$router.currentRoute.name
            }}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- <el-tabs
            v-model="editableTabsValue"
            type="card"
            editable
            @edit="handleTabsEdit"
          >
            <el-tab-pane
              :key="item.name"
              v-for="(item, index) in editableTabs"
              :label="item.title"
              :name="item.name"
            >
              {{ item.content }}
            </el-tab-pane>
          </el-tabs> -->
          <!-- <div
            class="homeWelcome"
            v-if="this.$router.currentRoute.path == '/admin/home'"
          >
            欢迎来到小L星光站！
          </div> -->
          <el-card
            class="main-content"
            v-loading="this.$store.state.loading"
            element-loading-text="向远方请求中"
          >
            <Index v-if="this.$router.currentRoute.path == '/'"></Index>
            <router-view />
          </el-card>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
 
<script>
import Index from "./components/Index.vue";
export default {
  name: "Home",
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem("user")), //这样得到的数据是字符串，要用JSON.parse方法吧字符串转换成json数据
      editableTabsValue: "2",
    };
  },
  components: {
    Index,
  },
  methods: {
    commandHandler(cmd) {
      //该方法有一个参数，cmd
      if (cmd == "logout") {
        this.$confirm("此操作将注销登录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.getRequest("/logout");
            window.sessionStorage.removeItem("user");
            this.$router.replace("/");
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消注销",
            });
          });
      }
    },
  },
  computed: {
    routers: function () {
      return this.$router.options.routes
        .filter((user) => {
          return !user.hidden;
        })
        .map((user) => {
          if (user.children) {
            user.children = user.children.filter((user) => {
              return !user.hidden;
            });
          }
          return user;
        });
    },
  },
  created() {},
};
</script>
 
<style>
.homeHeader {
  background-color: #409eff;
  display: flex;
  align-items: center; /*竖轴上居中*/
  justify-content: space-between; /*空白的地方在中间*/
  padding: 0 15px;
  box-sizing: border-box;
}
/* 字体样式 */
.title {
  font-size: 30px;
  font-family: 华文行楷;
  color: #ffffff;
}
/*设置鼠标移上去显示为手指*/
.userInfo {
  cursor: pointer;
}
/* 头像样式 */
.el-dropdown-link img {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 8px;
}
/* 用户名样式 */
.el-dropdown-link {
  display: flex;
  align-items: center;
}
/* 面包屑样式 */
.homeWelcome {
  text-align: center;
  font-size: 30px;
  font-family: 华文行楷;
  color: #409eff;
  padding-top: 50px;
}
a {
  text-decoration: none;
}
.main-container {
  margin-left: 228px;
}
.main-content {
  min-height: 80vh;
  margin-top: 20px;
}
.menu-container {
  position: fixed;
}
</style>

